﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;


namespace MVC.Models
{
    public class SampleData : CreateDatabaseIfNotExists<JardimEntities>
    {
        protected override void Seed(JardimEntities context)
        {
           

            new List<Ementa>()
            {
               new Ementa { Sobremesa = "Pudim", Sopa="Caldo Verde" },
               new Ementa { Sobremesa = "Arroz Doce", Sopa="Creme de Cenoura" },
               new Ementa { Sobremesa= "Laranja", Sopa="Creme de Abobora" },
               new Ementa { Sobremesa= "Maça", Sopa="Feijão Verde"},
               new Ementa { Sobremesa= "Banana", Sopa="Canja" },

            }.ForEach(a => context.Ementas.Add(a));
            context.SaveChanges();

            new List<Sala>()
            {
               new Sala { NomeSala="Joaninhas", Observacoes="Alunos com 3 anos"}, 
               new Sala { NomeSala="Borboletas", Observacoes="Alunos com 5 anos"},

            }.ForEach(a => context.Salas.Add(a));
            context.SaveChanges();
            
            new List<Pessoa>()
            {
              new Pessoa { Nome="Joao Afonso Ferreira", Morada="Rua das Papoilas nº 69 1º Esquerdo, Cidade do Congo 3900-278", NumeroContribuinte=11934239 , Telefone=265221122, Telemovel=96221122, Email="Joao_Afonso@hotmail.com", UserId="5e11dd40-b134-4c08-9580-a74954ebcca9", Role="EE" },
              new Pessoa { Nome="Maria Joana", Morada="Rua dos Girassois nº 30 2º Direito, Lisboa 2900-258", NumeroContribuinte=1357854 , Telefone=21994455, Telemovel=91457691, Email="maria.joana@gmail.com", UserId="59451a54-cedb-4ba4-864c-eb63b9c2de66", Role="Funcionario" },
              new Pessoa { Nome="Joaquim das Picoito", Morada="Rua das Couves nº 2 11º Direito, Porto 1900-134", NumeroContribuinte=15890912 , Telefone=23458712, Telemovel=93091234, Email="picoito99@sapo.pt", UserId="023ff6ba-cf59-4ece-97f0-d7cae2b93278", Role="Administrador" },
            }.ForEach(a => context.Pessoas.Add(a));
            context.SaveChanges();

            new List<Crianca>()
            {
                new Crianca { Frequenta=true, Nome="Ana Filipa", DataNascimento= new DateTime(2005,1,13), Observacoes="Alergico a Amendoins", 
                Pessoa=(from p in context.Pessoas.ToList() 
                where (p.Nome == "Joao Afonso Ferreira") 
                select p).FirstOrDefault(),
                Sala=(from p in context.Salas.ToList() 
                where (p.NomeSala == "Joaninhas") 
                select p).FirstOrDefault() },
            }.ForEach(a => context.Criancas.Add(a));
            context.SaveChanges();

            new List<Quota>()
            {
                new Quota { EstadoPago=true, Valor=100, Data=new DateTime(2012,10,11), Crianca= (from p in context.Criancas.ToList() 
                where (p.Nome == "Ana Filipa") 
                select p).FirstOrDefault()},
                new Quota { EstadoPago=false, Valor=200, Data=new DateTime(2012,10,11), Crianca= (from p in context.Criancas.ToList() 
                where (p.Nome == "Ana Filipa") 
                select p).FirstOrDefault()},
            }.ForEach(a => context.Quotas.Add(a));
            context.SaveChanges();

            new List<LevaCrianca>()
            {
                new LevaCrianca { NomePessoa="Mariana Rosa", BI=12345678 , Crianca= (from p in context.Criancas.ToList() 
                where (p.Nome == "Ana Filipa") 
                select p).FirstOrDefault()},
                new LevaCrianca { NomePessoa="Ze Afonso Ferreira", BI=87654321, Crianca= (from p in context.Criancas.ToList() 
                where (p.Nome == "Ana Filipa") 
                select p).FirstOrDefault()},
            }.ForEach(a => context.LevaCriancas.Add(a));
            context.SaveChanges();

            new List<Prato>()
            {
               new Prato { NomePrato="Peixe Cozido" },
               new Prato { NomePrato="Bacalhau á Brás" },
               new Prato { NomePrato="Lasanha" },
               new Prato { NomePrato="Hamburger com batata" },
               new Prato { NomePrato="Cozido á Portuguesa" },
               new Prato { NomePrato="Filetes com arroz" },
               new Prato { NomePrato="Carne á Bolonhesa" },
               new Prato { NomePrato="Peixe Assado com batatas" },
               new Prato { NomePrato="Feijoada" },
               new Prato { NomePrato="Pizza" },

            }.ForEach(a => context.Pratos.Add(a));
            context.SaveChanges();

            new List<ListaPratos>()
            {
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 1) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 2) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 3) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 4) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },
                 new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 9) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },

              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 1) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 4) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 5) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 6) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },
                new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 10) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },

               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 2) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 6) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 7) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 8) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },
                new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 9) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },

              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 3) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 4) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 5) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 6) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },
                 new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 10) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },

                new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 1) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 2) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 7) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 8) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },
                new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 9) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },

            }.ForEach(a => context.ListaPratos.Add(a));
            context.SaveChanges();  

                        

            new List<DiaEscolar>
            {
                new DiaEscolar { Dia= new DateTime(2012,1,23),  Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault()}, 
                new DiaEscolar {  Dia= new DateTime(2012,1,24),Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault()},
                new DiaEscolar {  Dia= new DateTime(2012,1,25),Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault()},
                new DiaEscolar {  Dia= new DateTime(2012,1,26),Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault()},
                new DiaEscolar {  Dia= new DateTime(2012,1,27),Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault()},
                 new DiaEscolar {  Dia= new DateTime(2012,1,30),Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault()},
            }.ForEach(a => context.DiaEscolars.Add(a));
            context.SaveChanges();

            new List<Evento>
            {
                new Evento { NomeEvento= "Evento1", Descricao= "Bue fixe", HoraFim=13 , HoraInicio=9, 
                    DiaEscolar= (from p in context.DiaEscolars.ToList() 
                where (p.DiaEscolarId == 1) 
                select p).FirstOrDefault(),
                Sala= (from p in context.Salas.ToList() 
                where (p.NomeSala == "Joaninhas") 
                select p).FirstOrDefault()},
                new Evento { NomeEvento= "Evento2", Descricao= "Bue mau", HoraFim=13 , HoraInicio=8, 
                    DiaEscolar= (from p in context.DiaEscolars.ToList() 
                where (p.DiaEscolarId == 1) 
                select p).FirstOrDefault(),
                Sala= (from p in context.Salas.ToList() 
                where (p.NomeSala == "Borboletas") 
                select p).FirstOrDefault()},
                new Evento { NomeEvento= "Evento3", Descricao= "Bue mau", HoraFim=13 , HoraInicio=8, 
                    DiaEscolar= (from p in context.DiaEscolars.ToList() 
                where (p.DiaEscolarId == 6) 
                select p).FirstOrDefault(),
                Sala= (from p in context.Salas.ToList() 
                where (p.NomeSala == "Joaninhas") 
                select p).FirstOrDefault()},
            }.ForEach(a => context.Eventos.Add(a));
            context.SaveChanges();

            //for (int i = 1; i < 1000; i++)
            //{
            //    new List<Prato>()
            //{
            //   new Prato { NomePrato="Peixe Cozido" },
            //}.ForEach(a => context.Pratos.Add(a));
            //    context.SaveChanges();
            //}

        }
    }
}